from django.db import models

# Create your models here.
import datetime

from django.contrib.auth.models import AbstractUser
from django.db import models

# Create your models here.
from django.utils import timezone
from django.contrib import admin


# class Question(models.Model):
#     question_text = models.CharField(max_length=200)
#     pub_date = models.DateTimeField('date published')
#
#     def __str__(self):
#         return self.question_text
#
#     @admin.display(
#         boolean=True,
#         ordering='pub_date',
#         description='Published recently?',
#     )
#     def was_published_recently(self):
#         return self.pub_date >= timezone.now() - datetime.timedelta(days=1)


# class Choice(models.Model):
#     question = models.ForeignKey(Question, on_delete=models.CASCADE)
#     choice_text = models.CharField(max_length=200)
#     votes = models.IntegerField(default=0)
#
#     def __str__(self):
#         return self.choice_text


class UserInfo(AbstractUser):
    token = models.CharField(max_length=128)
    refresh_times = models.IntegerField(default=0, null=True)

    def __str__(self):
        return self.username


class Movie(models.Model):
    id = models.CharField(verbose_name="电影ID", unique=True, primary_key=True, max_length=30)
    rating = models.CharField(max_length=20)
    rank = models.IntegerField()
    cover_url = models.URLField(verbose_name="封面图片", max_length=255)  # upload_to='movie_cover')
    types = models.CharField(verbose_name="电影类别", max_length=120)
    regions = models.CharField(max_length=120)
    title = models.CharField(max_length=255, verbose_name="电影名称")
    url = models.URLField()
    # release_date = models.DateTimeField()
    release_date = models.CharField(max_length=20)
    vote_count = models.IntegerField(verbose_name="评分数", default=0)
    score = models.FloatField(verbose_name="豆瓣电影评分")
    actors = models.CharField(verbose_name="主演", max_length=1024)
    info_summary = models.CharField(max_length=1024, verbose_name="电影简介", default='', null=True)
    tags = models.CharField(max_length=120, verbose_name='标签')
    director = models.CharField(max_length=50, verbose_name='导演', default='', null=True)

    def __str__(self):
        return self.title


class Favorites(models.Model):
    user = models.ForeignKey(UserInfo, on_delete=models.CASCADE)
    movie = models.ForeignKey(Movie, on_delete=models.CASCADE)
    is_like = models.BooleanField(default=None, null=True)
    pub_date = models.DateTimeField()

    def __str__(self):
        return self.is_like


class RecommendList(models.Model):
    user = models.ForeignKey(UserInfo, on_delete=models.CASCADE)
    movie = models.ForeignKey(Movie, on_delete=models.CASCADE)

    def __str__(self):
        return "recom"


class TagRecommendList(models.Model):
    user = models.ForeignKey(UserInfo, on_delete=models.CASCADE)
    movie = models.ForeignKey(Movie, on_delete=models.CASCADE)

    def __str__(self):
        return "tag"


class AdRecommendList(models.Model):
    user = models.ForeignKey(UserInfo, on_delete=models.CASCADE)
    movie = models.ForeignKey(Movie, on_delete=models.CASCADE)

    def __str__(self):
        return "Ad"


class SummaryRecommendList(models.Model):
    user = models.ForeignKey(UserInfo, on_delete=models.CASCADE)
    movie = models.ForeignKey(Movie, on_delete=models.CASCADE)

    def __str__(self):
        return "Sum"

#
# class WeightC(models.Model):
#     user = models.ForeignKey(UserInfo, on_delete=models.CASCADE)
#     type_id = models.IntegerField(max)
#     w = models.DecimalField(decimal_places=7, max_digits=12)
#
#     def __str__(self):
#         return "weight"

class BigCover(models.Model):
    movie_id = models.CharField(verbose_name="电影ID", default='',max_length=30)
    name = models.CharField(verbose_name="首页轮播", max_length=120)
    link = models.URLField(default=None, null=True)